package com.zhtools.wx.bean;

import com.zhtools.wx.utils.WXPayUtil;

import java.io.Serializable;
import java.util.Map;

/**
 * @author zhanghao
 * 获取沙箱密钥接口返回结果
 */
public class GetSandBoxSecretResponse implements Serializable {
    private static final long serialVersionUID = -5531281321421956744L;

    private String returnCode;
    private String returnMsg;
    private String mchId;
    private String sandBoxSignkey;

    public GetSandBoxSecretResponse() {
    }

    public String getReturnCode() {
        return returnCode;
    }

    public void setReturnCode(String returnCode) {
        this.returnCode = returnCode;
    }

    public String getReturnMsg() {
        return returnMsg;
    }

    public void setReturnMsg(String returnMsg) {
        this.returnMsg = returnMsg;
    }

    public String getMchId() {
        return mchId;
    }

    public void setMchId(String mchId) {
        this.mchId = mchId;
    }

    public String getSandBoxSignkey() {
        return sandBoxSignkey;
    }

    public void setSandBoxSignkey(String sandBoxSignkey) {
        this.sandBoxSignkey = sandBoxSignkey;
    }

    /**
     * 根据xml响应结果构建实例
     *
     * @param xml
     * @return
     */
    public static GetSandBoxSecretResponse build(String xml) {
        Map<String, String> responseMap = null;
        try {
            responseMap = WXPayUtil.xmlToMap(xml);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(responseMap == null){
            return null;
        }
        GetSandBoxSecretResponse instance = new GetSandBoxSecretResponse();
        instance.setReturnCode(responseMap.get("return_code"));
        instance.setReturnMsg(responseMap.get("return_msg"));
        instance.setMchId(responseMap.get("mch_id"));
        instance.setSandBoxSignkey(responseMap.get("sandbox_signkey"));
        return instance;
    }

    @Override
    public String toString() {
        return "GetSandBoxSecretResponse{" +
                "returnCode='" + returnCode + '\'' +
                ", returnMsg='" + returnMsg + '\'' +
                ", mchId='" + mchId + '\'' +
                ", sandBoxSignkey='" + sandBoxSignkey + '\'' +
                '}';
    }
}
